package com.tgy.shiroboot.controller;

import com.tgy.shiroboot.entity.User;
import com.tgy.shiroboot.mapper.UserMapper;
import org.apache.catalina.security.SecurityUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/***
 * @ClassName: UserController
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 10:37 2022/1/6
 * @version : V1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    UserMapper userMapper;

    @RequestMapping("/all")
    public Map<String, Object> getAll(){

        return null;
    }

    @RequestMapping("/getUserByName")
    public Map<String, Object> getAll(@RequestParam("name") String username){
        User user = userMapper.getUserByName(username);
        return null;
    }

    @RequestMapping("/unauth")
    @ResponseBody
    public String unauthorized(){
        return "未经授权无法访问";
    }

    @RequestMapping("/logout")
    @ResponseBody
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "已退出";
    }
}
